package com.ruiyian.project.equipment.controller;

import com.ruiyian.common.core.controller.BaseController;
import com.ruiyian.common.core.domain.AjaxResult;
import com.ruiyian.common.core.page.TableDataInfo;
import com.ruiyian.common.core.domain.entity.Equipment;
import com.ruiyian.project.equipment.domain.EquipmentType;
import com.ruiyian.project.equipment.service.EquipmentTypeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author chong
 * @email 673426164@qq.com
 * @create 2021/1/25
 * Desc: 设备类型
 */
@Slf4j
@RequestMapping("/equipment/equipmentType")
@RestController
public class EquipmentTypeController extends BaseController {
    @Autowired
    private EquipmentTypeService equipmentTypeService;

    /**
     * 获取列表
     * @param equipmentType
     * @return
     */
    @PostMapping("/list")
    public AjaxResult list(@RequestBody EquipmentType equipmentType) {
        List<EquipmentType> list = null;
        try {
            list = equipmentTypeService.selectList(equipmentType);
        } catch (Exception e) {
            logger.error(e.getMessage());
            return AjaxResult.error(e.getMessage());
        }
        return AjaxResult.success(list);
    }

    /**
     * 保存
     * @param equipmentType
     * @return
     */
    @PostMapping("/save")
    public AjaxResult save(@RequestBody EquipmentType equipmentType) {
        try {
            if(equipmentType.getId()!=null){
                equipmentTypeService.edit(equipmentType);
            }else {
                equipmentTypeService.save(equipmentType);
            }
        } catch (Exception e) {
            logger.error(e.getMessage());
            return AjaxResult.error(e.getMessage());
        }
        return AjaxResult.success(equipmentType);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody Long id) {
        try {
            equipmentTypeService.delete(id);
        } catch (Exception e) {
            logger.error(e.getMessage());
            return AjaxResult.error(e.getMessage());
        }
        return AjaxResult.success();
    }
}
